
package org.puremvc.as3.multicore.demos.flex.hellopipes.modules.simplemodule.view
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.multicore.demos.flex.hellopipes.modules.simplemodule.ApplicationFacade;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class SimpleModuleMediator extends Mediator
	{
		//
		// vars

		//
		// const	
		public static const NAME: String = 'SimpleModuleMediator';
		
		//
		// instances

		
				
		public function SimpleModuleMediator( viewComponent: SimpleModule )
		{
			super( NAME, viewComponent );
		}

		/**
		 * Register event listeners
		 */
		override public function onRegister():void
		{
			simpleModule.addEventListener( SimpleModule.SAY_HELLO_TO_SHELL, sayHelloToShellHandler );
			simpleModule.addEventListener( SimpleModule.DISPOSE, diposeHandler );
		
		}

		/**
		 * Remove event listeners
		 */
		override public function onRemove():void
		{
			simpleModule.removeEventListener( SimpleModule.SAY_HELLO_TO_SHELL, sayHelloToShellHandler );
			simpleModule.removeEventListener( SimpleModule.DISPOSE, diposeHandler );
		
		}		
		/**
		 * Notification list.
		 */
		override public function listNotificationInterests():Array
		{
			return [  ];	
		}
		
		/**
		 * Handle notifications.
		 */
		override public function handleNotification( note:INotification ):void
		{

		}
		
		/**
		 * The view component which is the Simple Module.
		 */
		private function get simpleModule(): SimpleModule
		{
			return viewComponent as SimpleModule;
		}

		/**
		 * Display new message received from shell
		*/		
		public function updateMessages( messages: ArrayCollection):void
		{
			simpleModule.showMessagesSendedFromShell( messages );
		}
		
		
		//--------------------------------------------------------------------------
		//
		// callbacks for handling events dispatched by SimpleModule
		//
		//--------------------------------------------------------------------------
		
					
		private function sayHelloToShellHandler( event: Event ):void
		{
			sendNotification( ApplicationFacade.SEND_MESSAGE_TO_SHELL, 
								"Hello Shell, I'm a message sended from module" );		
		}

		private function diposeHandler( event: Event ):void
		{

			sendNotification( ApplicationFacade.DISPOSE );		
		}
			
	}
}